package cn.piaoyi.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.piaoyi.bean.Admin;
import cn.piaoyi.bean.Comment;
import cn.piaoyi.bean.Goods;
import cn.piaoyi.bean.UserInfo;
import cn.piaoyi.comm.Constant;
import cn.piaoyi.comm.Util;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.AdminService;
import cn.piaoyi.service.CommentService;
import cn.piaoyi.service.UserInfoService;
import cn.piaoyi.service.web.PageList;
import cn.piaoyi.service.web.Pages;
import cn.piaoyi.web.interceptor.UserSessionAware;
import cn.piaoyi.web.servlet.AdminSession;
import cn.piaoyi.web.servlet.UserSession;
import cn.piaoyi.web.ui.OptionsInt;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

public class CommentAction extends BaseAction implements SessionAware,UserSessionAware{
	private static final Log logger = LogFactory.getLog(CommentAction.class);
	
	private CommentService commentService;

	public CommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}
	
	private UserSession userSession;
	private Map session;

	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	public Map getSession() {
		return session;
	}
	
	public void setSession(Map session) {
		this.session = session;
	}
	
	private long id;				//ID
	private String message= "";
	

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		Comment c = new Comment();
		c.setGoodsId(this.id);
		c.setUserId(getUserSession().getUid());
		c.setMessage(this.message);
		c.setAddTime(new Date());
		c.setReply("");
		c.setReplyTime(new Date());
		c.setIsShow(1);
		try {
			this.getCommentService().createComment(c);
		} catch (PiaoyiException e) {
			this.addActionError(this.getText("error.saveerror"));
			return ERROR;
		}
		return SUCCESS;
	}
}
